package com.msb.dongbao.portal.web.controller;

import com.msb.dongbao.common.base.annotations.TokenCheck;
import com.msb.dongbao.common.base.result.ResultWrapper;
import com.msb.dongbao.common.util.JwtUtil;
import com.msb.dongbao.ums.entity.UmsMember;
import com.msb.dongbao.ums.entity.dto.UmsMemberLoginParamDTO;
import com.msb.dongbao.ums.entity.dto.UmsMemberRegisterParamDTO;
import com.msb.dongbao.ums.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author: mayu
 * @date: 2021年05月26日 17:32
 */
@RestController
@RequestMapping("/ums-member")
public class UmsMemberController {

    @Autowired
    UmsMemberService umsMemberService;

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

    /**
     * 获取验证码
     *
     * @return java.lang.String
     */
    @GetMapping("/get-captcha")
    public String getCaptcha() {
        return "获取验证码";
    }

    /**
     * 注册
     *
     * @param umsMemberParamDTO
     * @return ResultWrapper
     */
    @PostMapping("/register")
    public ResultWrapper register(@RequestBody @Valid UmsMemberRegisterParamDTO umsMemberParamDTO) {
        //int i = 1/0;
        return umsMemberService.register(umsMemberParamDTO);
    }

    /**
     * 登录
     *
     * @param umsMemberLoginParamDTO
     * @return java.lang.String
     */
    @PostMapping("/login")
    public ResultWrapper login(@RequestBody UmsMemberLoginParamDTO umsMemberLoginParamDTO) {
        return umsMemberService.login(umsMemberLoginParamDTO);
    }

    @PostMapping("/edit")
    @TokenCheck
    public ResultWrapper edit(@RequestBody UmsMember umsMember) {
        return umsMemberService.edit(umsMember);
    }

    /**
     * 验证token
     *
     * @param token
     * @return java.lang.String
     */
    @GetMapping("/test-verify")
    public String verify(String token) {
        return JwtUtil.parseToken(token);
    }
}
